package com.grupoconstruobras.sigo.exhumaciones.ui.listener;

import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;

public class MessagesValidatorListener {
	
	private List<FacesMessage> messages;
	
	public MessagesValidatorListener(List<FacesMessage> messages) {
		this.messages = messages;
	}
	
	public void messages(ComponentSystemEvent event) {
		this.messages.clear();
		FacesContext fc = FacesContext.getCurrentInstance();
		if(fc.isValidationFailed()) {
			for(FacesMessage message : fc.getMessageList()) {
				if(message.getSeverity() == FacesMessage.SEVERITY_ERROR) {
					this.messages.add(message);
				}
			}
		}
	}

}
